﻿// This code is released under the BSD license.
namespace PugLib.UnitTest
{
    #region

    using System;
    using Functional;
    using Microsoft.VisualStudio.TestTools.UnitTesting;

    #endregion

    /// <summary>
    ///This is a test class for YTest and is intended
    ///to contain all YTest Unit Tests
    ///</summary>
    [TestClass]
    public class YTest
    {
        /// <summary>
        ///A test for Combine
        ///</summary>
        public void CombineTestHelper()
        {
            Func<int, int> fib = Y.Combine<int, int>(f => n => n > 1 ? f(n - 1) + f(n - 2) : n);
            Func<int, int> fact = Y.Combine<int, int>(f => n => n > 1 ? n * f(n - 1) : 1);

            const int expectedFib = 8;
            const int expectedFact = 720;

            Assert.AreEqual(expectedFib, fib(6));
            Assert.AreEqual(expectedFact, fact(6));
        }

        [TestMethod]
        public void CombineTest()
        {
            CombineTestHelper();
        }
    }
}